<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <kfm-table
        :table-data="tableData"
        :titles="titles"
        :props="props"
        background-color="#ccc"
        color="#fff"
      >
        <kfm-table-item></kfm-table-item>
      </kfm-table>
    </div>
    <script src="../vue/vue.global.js"></script>
    <script>
      const app = Vue.createApp({
        data() {
          return {
            tableData: [
              {
                date: "2021-06-01",
                name: "王小虎1",
                address: "上海市普陀区金沙江路 1518 弄",
              },
              {
                date: "2021-06-02",
                name: "王小虎2",
                address: "上海市普陀区金沙江路 1517 弄",
              },
              {
                date: "2021-06-03",
                name: "王小虎3",
                address: "上海市普陀区金沙江路 1519 弄",
              },
              {
                date: "2021-06-04",
                name: "王小虎4",
                address: "上海市普陀区金沙江路 1516 弄",
              },
            ],
            titles: ["日期", "姓名", "地址"],
            props: ["date", "name", "address"],
          };
        },
      });

      const kfmTable = {
        props: {
          tableData: {
            type: Array,
            required: true,
          },
          props: {
            type: Array,
            required: true,
          },
          titles: {
            type: Array,
            required: true,
          },
          backgroundColor: {
            type: String,
            default: "#fff",
          },
          color: String,
        },
        data() {},
        methods: {},
        template: `
            <table border='1' cellpadding='0' cellspacing='0' :style="{ 'background-color': backgroundColor, 'color': color }">
                <thead>
                    <tr>
                        <th v-for='item in titles'>{{ item }}</th>
                    </tr>
                </thead>
                <tbody>
                    <tr v-for='item in tableData'>
                        <td v-for='prop in props'>{{ item[prop] }}</td>
                    </tr>
                </tbody>
            </table>
        `,
      };

      app.component("kfm-table", kfmTable);
      app.mount("#app");
    </script>
  </body>
</html>
